
import * as constants from '@/utils/constants.js'
import { formatDates } from '@/utils/index'
import i18n from '../../lang'
// 公共过滤器
export function filterEmpty(val) {
  let _result = '-'
  if (!val) {
    return _result
  }
  _result = val
  return _result
}

// 时间过滤器
export function formatDate(time) {
  if (time !== 0) {
    const date = new Date(time * 1000)
    return formatDates(date, 'yyyy-MM-dd hh:mm')
  }
}

export function filterYesOrNo(value, $t) {
  return value ? i18n.t('yes') : i18n.t('no')
}

export function filterShowOrHide(value) {
  return value ? i18n.t('xianShi') : i18n.t('buXianShi')
}

export function filterShowOrHideForFormConfig(value) {
  return value === '‘0’' ? i18n.t('xianShi') : i18n.t('buXianShi')
}

export function filterYesOrNoIs(value) {
  return value ? i18n.t('no') : i18n.t('yes')
}

export function filterCategroyType(value) {
  return constants.categoryType.filter((item) => value === item.value)[0].name
}

export function filterConfigCategory(value) {
  return constants.configCategory.filter((item) => value === item.value)[0].label
}

/**
 * @description 公众号回复类型
 */
export function keywordStatusFilter(status) {
  const statusMap = {
    text: i18n.t('wenZiXiaoXi'),
    image: i18n.t('tuPianXiaoXi'),
    news: i18n.t('tuWenXiaoXi'),
    voice: i18n.t('shengYinXiaoXi')
  }
  return statusMap[status]
}

/**
 * @description 优惠券类型
 */
export function couponTypeFilter(status) {
  const statusMap = {
    1: i18n.t('shangJiaQuan'),
    2: i18n.t('shangPinQuan')
  }
  return statusMap[status]
}

/**
 * @description 优惠券领取方式
 */
export function couponUserTypeFilter(status) {
  const statusMap = {
    1: i18n.t('shouDongLingQu'),
    3: i18n.t('zengSongQuan')
  }
  return statusMap[status]
}

/**
 * @description 文章分类
 */
export function articleTypeFilter(status) {
  if (!status) {
    return ''
  }
  const arrayList = JSON.parse(localStorage.getItem('articleClass'))
  if (arrayList.filter((item) => Number(status) === Number(item.id)).length < 1) {
    return ''
  }
  return arrayList.filter((item) => Number(status) === Number(item.id))[0].name
}

/**
 * @description 支付状态
 */
export function payStatusFilter(status) {
  const statusMap = {
    false: i18n.t('weiZhiFu'),
    true: i18n.t('yiZhiFu')
  }
  return statusMap[status]
}

/**
 * @description 提现方式
 */
export function extractTypeFilter(status) {
  const statusMap = {
    bank: i18n.t('yinHangKa'),
    alipay: i18n.t('zhiFuBao'),
    weixin: i18n.t('weiXin')
  }
  return statusMap[status]
}

/**
 * @description 充值类型
 */
export function rechargeTypeFilter(status) {
  const statusMap = {
    public: i18n.t('weiXinGongZhongHao'),
    weixinh5: i18n.t('weiXinH5ZhiFu'),
    routine: i18n.t('xiaoChengXu')
  }
  return statusMap[status]
}

/**
 * @description 财务审核状态
 */
export function extractStatusFilter(status) {
  const statusMap = {
    '-1': i18n.t('yiJuJue'),
    0: i18n.t('shenHeZhong'),
    1: i18n.t('yiTiXian')
  }
  return statusMap[status]
}

/**
 * @description 砍价状态
 */
export function bargainStatusFilter(status) {
  const statusMap = {
    1: i18n.t('jinHangZhong'),
    2: i18n.t('weiWanCheng'),
    3: i18n.t('yiChengGong')
  }
  return statusMap[status]
}

/**
 * @description 砍价状态
 */
export function bargainColorFilter(status) {
  const statusMap = {
    1: '',
    2: 'danger',
    3: 'success'
  }
  return statusMap[status]
}

/**
 * @description 拼团状态
 */
export function groupStatusFilter(status) {
  const statusMap = {
    1: i18n.t('jinHangZhong'),
    2: i18n.t('yiChengGong'),
    3: i18n.t('weiWanCheng')
  }
  return statusMap[status]
}

/**
 * @description 拼团状态
 */
export function groupColorFilter(status) {
  const statusMap = {
    1: '',
    2: 'success',
    3: 'danger'
  }
  return statusMap[status]
}

/**
 * @description 一号通tab值
 */
export function onePassTypeFilter(status) {
  const statusMap = {
    sms: i18n.t('duanXin'),
    copy: i18n.t('shangPinCaiJi'),
    expr_query: i18n.t('wuLiuChaXun'),
    expr_dump: i18n.t('dianZiMianDanDaYin')
  }
  return statusMap[status]
}

/**
 * @description 视频号商品草稿状态
 */
export function editStatusFilter(status) {
  const statusMap = {
    1: i18n.t('weiShenHe'),
    2: i18n.t('shenHeZhong'),
    3: i18n.t('shenHeShiBai'),
    4: i18n.t('shenHeChengGong')
  }
  return statusMap[status]
}

/**
 * @description 视频号正式商品状态
 */
export function videoStatusFilter(status) {
  const statusMap = {
    0: i18n.t('chuShiZhi'),
    5: i18n.t('shangjia'),
    11: i18n.t('ziZhuXiaJia'),
    13: i18n.t('weiGuiXiaJiaFengKongXiTongXiaJia')
  }
  return statusMap[status]
}

/**
 * @description 角色类型
 */
export function roleTypeFilter(status) {
  const statusMap = {
    platform: i18n.t('pingTai'),
    merchant: i18n.t('shangHu'),
    system: i18n.t('xiTong')
  }
  return statusMap[status]
}
